<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="会员名称" prop="memberName">
        <el-input
          v-model="queryParams.memberName"
          placeholder="请输入会员名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:records:add']"
        >新增</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['system:records:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:records:remove']"
        >删除</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['system:records:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="recordsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" width="100" align="center" prop="id" />
      <el-table-column label="会员名称" width="180" align="center" prop="memberName" />
      <el-table-column label="权益类型" width="180" align="center" prop="memberType" >
      <template slot-scope="scope">
        <span>{{ parseType(scope.row.memberType) }}</span>
      </template>
      </el-table-column>
      <el-table-column label="权益使用描述" align="center" prop="remark" />
      <el-table-column label="创建时间" width="240" align="center" prop="createTime" />
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['system:records:edit']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['system:records:remove']"-->
<!--          >删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改会员权益使用记录表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="选择会员" prop="memberId">
          <template>
            <el-select v-model="form.memberId" filterable placeholder="请选择会员">
              <el-option
                v-for="item in memberList"
                :key="item.id"
                :label="item.memberName"
                :value="item.id">
              </el-option>
            </el-select>
          </template>
        </el-form-item>
        <el-form-item label="选择" prop="memberCradId">
          <template>
            <el-select v-model="form.memberType" filterable placeholder="请选择">
              <el-option
                v-for="item in memberTypeList"
                :key="item.memberType"
                :label="item.memberTypeName"
                :value="item.memberType">
              </el-option>
            </el-select>
          </template>
        </el-form-item>
        <el-form-item label="权益使用描述" prop="remark">
          <el-input type="textarea" rows="5" placeholder="使用权益的描述-如：XXX会员使用了一次公司提供的内部干净舒适的约会环境" v-model="form.remark"></el-input>
        </el-form-item>
        <el-form-item label="权益说明">
          <span style="color: red">注意：权益使用一次就少一次</span>
          <br />
          权益1：专属心理匹配测试及剖析解读次数
          <br />
          权益2：高端猎婚专业婚恋情感分析次数
          <br />
          权益3：整体形象造型设计指导次数
          <br />
          权益4：建立专属爱情资料数据库，面对面优化征婚方案
          <br />
          权益5：资深婚恋老师全程跟踪、指导，筛选、安排一对一约见次数
          <br />
          权益6：提供公司内部干净舒适的约会环境次数
          <br />
          权益7：专享线上平台（钻石会员）优先展示特权和追求权限，置顶 次数
          <br />
          权益8：富顺城恋公众号发布个人征婚信息次数
          <br />
          权益9：红娘朋友圈发布个人征婚信息次数
          <br />
          权益10：参加内部和政企单位相亲活动次数，并享受优先获得合适异性料和推荐的 VIP 权限
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRecords, getRecords, delRecords, addRecords, updateRecords } from "@/api/business/records";
import {getMemberList} from "@/api/business/member"
export default {
  name: "Records",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 会员权益使用记录表表格数据
      recordsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        memberId: null,
        memberName: null,
        memberType: null,
        remark: null,
      },
      // 表单参数
      form: {},
      memberList:[],
      memberTypeList:[
        {memberType:1,memberTypeName:'权益一'},
        {memberType:2,memberTypeName:'权益二'},
        {memberType:3,memberTypeName:'权益三'},
        {memberType:4,memberTypeName:'权益四'},
        {memberType:5,memberTypeName:'权益五'},
        {memberType:6,memberTypeName:'权益六'},
        {memberType:7,memberTypeName:'权益七'},
        {memberType:8,memberTypeName:'权益八'},
        {memberType:9,memberTypeName:'权益九'},
        {memberType:10,memberTypeName:'权益十'}
      ],
      // 表单校验
      rules: {
        memberId: [
          { required: true, message: "选择会员不能为空", trigger: "blur" }
        ],
        memberType: [
          { required: true, message: "选择权益不能为空", trigger: "blur" }
        ],
        remark: [
          { required: true, message: "权益使用描述不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询会员权益使用记录表列表 */
    getList() {
      this.loading = true;
      listRecords(this.queryParams).then(response => {
        this.recordsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        memberId: null,
        memberName: null,
        memberType: null,
        remark: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加会员权益使用记录表";
      this.getMemberList();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRecords(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改会员权益使用记录表";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRecords(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRecords(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除会员权益使用记录表编号为"' + ids + '"的数据项？').then(function() {
        return delRecords(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/records/export', {
        ...this.queryParams
      }, `records_${new Date().getTime()}.xlsx`)
    },
    getMemberList(){
      getMemberList().then(response => {
        this.memberList = response.data;
      });
    },
    parseType(memberType){
      switch (memberType) {
        case 1:
          return '权益一';
        case 2:
          return '权益二';
        case 3:
          return '权益三';
        case 4:
          return '权益四';
        case 5:
          return '权益五';
        case 6:
          return '权益六';
        case 7:
          return '权益七';
        case 8:
          return '权益八';
        case 9:
          return '权益九';
        default:
          return '权益十';
      }
    }
  }
};
</script>
